package day0411;

public class Test09 {
    public static void main(String[] args) {
        int[][] arr = {
                {1, 2, 3},
                {4, 5, 6},
                {7, 8, 9}
        };
        int sum = 0;
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            sum += arr[i][i];
        }
        for (int i = 0; i < n; i++) {
            sum += arr[i][n - 1 - i];
        }
        if (n % 2 == 1) {
            sum -= arr[n / 2][n / 2];
        }
        System.out.println("3x3 二维数组对角线元素之和为: " + sum);
    }
}